package com.bluegalaxy.nhb.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bluegalaxy.nhb.core.XxSqlQueryJoin;
import com.bluegalaxy.nhb.domain.constant.SqlKeyConst;
import com.bluegalaxy.nhb.domain.constant.XxBuildConst;
import com.bluegalaxy.nhb.domain.enums.SqlOperEnum;
import com.bluegalaxy.nhb.service.AssembleService;

import com.bluegalaxy.nhb.sql.AssembleSql;
import com.bluegalaxy.nhb.util.StringUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import java.lang.reflect.Array;
import java.util.*;

/**
 * @author:
 * @date: 2021/6/23 12:59
 * @description:
 */
@Service("AssembleService")
public class AssembleServiceImpl implements AssembleService {

    private static Log log = LogFactory.getLog(AssembleServiceImpl.class);

    private static final String userAttributes = "userAttributes";  //用户属性
    private static final String userActions = "userActions";  //用户行为满足
    private static final String userActionOrders = "userActionOrders";  //行为序列

    /*********************用户画像各条件参数KEY***********************************************/
    private static String type = "type";
    private static String global_relation_key = "globalStr";  //key and/or
    private static String attribute_relation_key = "attributeStr";  //key and/or
    private static String action_relation_key = "actionStr";  //key and/or
    private static String order_relation_key = "orderStr";  //key and/or
    private static String and_value = "且";
    private static String or_value = "或";
    //用户属性
    private static String field_key = "attributeName";
    private static String function_key = "valueExpression";
    private static String params_key = "value1Str";
    private static String params2_key = "value2Str";
    //用户行为满足/行为序列
    private static String dataRange = "dataRange";

    private static String doThings = "doThings";
    private static String eventType = "eventType";

    private static String children = "eventItems";
    private static String e_eventItem = "eventItem";

    private static String e_field_key = "eventType";
    private static String e_function_key = "eventItemExpression";
    private static String e_params_key = "value1Str";
    private static String e_params2_key = "value2Str";

    private static String s_f_time = "time"; //ck sql字段，sql_filed_time
    private static String s_f_enent = "event"; //ck sql字段

    private static String table_events = "events"; //ck events表
    private static String table_users = "users"; //ck users表
    private static String events_alias = "e"; //ck users表
    private static String users_alias = "u"; //ck users表

    private static String relation_id = "e.login_id = u.login_id"; //关联id字段

    private static String distinct_id = "distinct_id";

    @Override
    public String assembleSql(JSONObject json, int assType){

//        log.info("json:"+json.toJSONString());
        //用户属性
        JSONArray attrArray = null;
        if (json.containsKey(userAttributes) && json.getJSONArray(userAttributes) != null){
            attrArray = json.getJSONArray(userAttributes);
        }
        //用户行为分析
        JSONArray actionArray = null;
        if (json.containsKey(userActions) && json.getJSONArray(userActions) != null){
            actionArray = json.getJSONArray(userActions);
        }
        //用户行为序列
        JSONArray orderArray = null;
        if (json.containsKey(userActionOrders) && json.getJSONArray(userActionOrders) != null){
            orderArray = json.getJSONArray(userActionOrders);
        }

        XxSqlQueryJoin xxSql = XxSqlQueryJoin.start();
        if (SqlKeyConst.COUNT == assType){
            xxSql.select(" count("+SqlKeyConst.DISTINCT+" "+distinct_id+") ");
        }else{
            xxSql.select(SqlKeyConst.DISTINCT+" "+distinct_id);
        }
        xxSql.from(table_events).text(events_alias);
        if (checkArray(attrArray,userAttributes)){
            xxSql.innerJoin(table_users).text(users_alias).on(relation_id);
        }
        String globalRelation = SqlOperEnum.getValue(json.getString(global_relation_key));
        if (StringUtil.isEmpty(globalRelation)) globalRelation = SqlKeyConst.AND.toLowerCase();

        String attributeRelation = SqlOperEnum.getValue(json.getString(attribute_relation_key));
        if (StringUtil.isEmpty(attributeRelation)) attributeRelation = SqlKeyConst.AND.toLowerCase();

        String actionRelation = SqlOperEnum.getValue(json.getString(action_relation_key));
        if (StringUtil.isEmpty(actionRelation)) actionRelation = SqlKeyConst.AND.toLowerCase();

        String orderRelation = SqlOperEnum.getValue(json.getString(order_relation_key));
        if (StringUtil.isEmpty(orderRelation)) orderRelation = SqlKeyConst.AND.toLowerCase();
//        xxSql.where(" 1=1 ");
        if (checkArray(attrArray,userAttributes)) {
            assemleArray(attrArray,userAttributes,globalRelation, attributeRelation, xxSql);
        }
        if (checkArray(actionArray,userActions)){
            assemleArray(actionArray,userActions,globalRelation, actionRelation,xxSql);
        }
        if (checkArray(orderArray,userActionOrders)){
            assemleArray(orderArray,userActionOrders,globalRelation, orderRelation,xxSql);
        }

//        assemleAttributes(orderArray, SqlKeyConst.AND,xxSql);

        String querySql = xxSql.end().getSql();
        log.info("querySql:"+querySql);
        return querySql;
    }

    private static void assemleArray(JSONArray jsonArray,String paramModule,String globalRelation,String relation,XxSqlQueryJoin xxSql){
        if (!Objects.isNull(jsonArray) && !jsonArray.isEmpty()) {
            if (!xxSql.get().getSql().contains(SqlKeyConst.WHERE)){
                xxSql.where("");
            }else{
                xxSql.text(" "+globalRelation+" ");
            }
            xxSql.text("( ");
            if (userActionOrders.equals(paramModule) || userActions.equals(paramModule)){
                xxSql.text(" "+distinct_id+" in (");
            }
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                switch (paramModule){
                    case userAttributes:
                        assemleAttributesObj(jsonObject,globalRelation, relation,i==0, xxSql);
                        break;
                    case userActions:
                        assemleActionObj(jsonObject,globalRelation, relation,paramModule,i==0, xxSql);
                        break;
                    case userActionOrders:
                        assemleOrderObj(jsonObject,globalRelation, relation,paramModule,i==0, xxSql);
                        break;

                    default:
                        assemleObject(jsonObject,paramModule,globalRelation, relation, xxSql);
                }
            }
            if (userActionOrders.equals(paramModule) || userActions.equals(paramModule)){
                xxSql.text(" ) ");
            }
            xxSql.text(" )");
        }
    }

    private static void assemleAttributes(JSONArray jsonArray,String paramModule,String globalRelation,String relation,XxSqlQueryJoin xxSql){
        if (!Objects.isNull(jsonArray) && !jsonArray.isEmpty()){
            if (!xxSql.get().getSql().contains(SqlKeyConst.WHERE)){
                xxSql.where("");
            }else{
                xxSql.text(" "+globalRelation+" ");
            }
            xxSql.text("( ");
            for(int i=0;i<jsonArray.size();i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                if (checkParamValue(jsonObject,userAttributes)){
                    assemleAttributesObj(jsonObject,globalRelation,relation,i==0,xxSql);
                }

            }
            xxSql.text(" )");
        }
    }

    private static void assemleAction(JSONArray jsonArray,String globalRelation,String relation,XxSqlQueryJoin xxSql){
        if (!Objects.isNull(jsonArray) && !jsonArray.isEmpty()){
            if (!xxSql.get().getSql().contains(SqlKeyConst.WHERE)){
                xxSql.where("");
            }else{
                xxSql.text(" "+globalRelation+" ");
            }
            xxSql.text("( ");
            for(int i=0;i<jsonArray.size();i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
//                assemleActionObj(jsonObject,relation,userActions,xxSql);
            }
            xxSql.text(" )");
        }
    }

    private static void assemleOrders(JSONArray jsonArray,String globalRelation,String relation,XxSqlQueryJoin xxSql){
        if (!Objects.isNull(jsonArray) && !jsonArray.isEmpty()){
            if (!xxSql.get().getSql().contains(SqlKeyConst.WHERE)){
                xxSql.where("");
            }else{
                xxSql.text(" "+globalRelation+" ");
            }
            xxSql.text("( ");
            for(int i=0;i<jsonArray.size();i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
//                assemleActionObj(jsonObject,relation,userActionOrders,xxSql);
            }
            xxSql.text(" )");
        }
    }

    private static boolean checkArray(JSONArray jsonArray,String checkType){
        if (!Objects.isNull(jsonArray) && !jsonArray.isEmpty()){
            if (userAttributes.equals(checkType)){
                for(int i=0;i<jsonArray.size();i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    if (checkParamValue(jsonObject,checkType)){
                        return true;
                    }
                }
            }
            if (userActions.equals(checkType)){
                for(int i=0;i<jsonArray.size();i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    if(jsonObject.containsKey(eventType) && !jsonObject.getJSONObject(eventType).isEmpty()){
                        if (checkParamValue(jsonObject,checkType)){
                            return true;
                        }
                    }
                }
            }

            if (userActionOrders.equals(checkType)){
                for(int i=0;i<jsonArray.size();i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);

                    JSONArray eventItems = jsonObject.getJSONArray(children);
                    for (int t=0;t<eventItems.size();t++){
                        JSONObject eventItem = eventItems.getJSONObject(t);
                        if (checkParamValue(eventItem,checkType)){
                            return true;
                        }
                    }
                }
            }

        }
        return false;
    }


    private static void assemleAttributesObj(JSONObject jsonObject,String globalRelation,String relation,boolean isFirst,XxSqlQueryJoin xxSql){

        if (checkParamValue(jsonObject,userAttributes)){
            String field = users_alias+"."+jsonObject.getString(field_key);
            String functionValue = jsonObject.getString(function_key);
            if (SqlKeyConst.BETWEEN.equals(functionValue)){
                AssembleSql.assemleBetween(field,
                        isFirst?SqlKeyConst.BETWEEN:relation+AssembleSql.capture(SqlKeyConst.BETWEEN),
                        jsonObject.get(params_key),jsonObject.get(params2_key),xxSql);
            }else if(functionValue.contains(SqlKeyConst.IN)){
                AssembleSql.assemleIn(field,
                        isFirst?SqlOperEnum.getValue(functionValue):relation+AssembleSql.capture(SqlOperEnum.getValue(functionValue)),
                        jsonObject.get(params_key),xxSql);
            }else {
                AssembleSql.assemle(field,
                        isFirst?SqlOperEnum.getValue(functionValue):relation+AssembleSql.capture(SqlOperEnum.getValue(functionValue)),
                        jsonObject.get(params_key),xxSql);
            }

        }
        if (jsonObject.containsKey(children) && jsonObject.get(children) != null){
            assemleAttributes(jsonObject.getJSONArray(children),userAttributes,globalRelation,
                    StringUtil.isNotEmpty(jsonObject.getString(relation))?jsonObject.getString(relation):SqlKeyConst.AND
                    ,xxSql);
        }

    }

    private static void assemleActionObj(JSONObject jsonObject,String globalRelation,String relation,String checkType,boolean isFirst,XxSqlQueryJoin xxSql){
        if (!jsonObject.containsKey(dataRange) || jsonObject.getJSONArray(dataRange) == null){
            return;
        }
        if (!isFirst){
            xxSql.unionAll();
        }
        xxSql.select(distinct_id).from(table_events).where("");

        //"dataRange":["2021-07-13","2021-07-29"]
        JSONArray range = jsonObject.getJSONArray(dataRange);
        String startDate = "";
        String endDate = "";
        if (!Objects.isNull(range) && !range.isEmpty()){
            startDate = range.getString(0);
            endDate = range.getString(1);
            AssembleSql.assemleBetween(s_f_time,SqlKeyConst.BETWEEN,startDate,endDate,xxSql);
        }

        //"doThings":"do","eventType":"MPShow"
        //用户行为满足 有以下参数
        JSONObject eventTypeObj = jsonObject.getJSONObject(eventType);
        if (eventTypeObj.containsKey(eventType) && jsonObject.containsKey(doThings)
                && StringUtil.isNotEmpty(eventTypeObj.getString(eventType)) && StringUtil.isNotEmpty(jsonObject.getString(doThings)))
        {
            String doStr = jsonObject.getString(doThings);
            AssembleSql.assemle(s_f_enent, SqlKeyConst.AND.toLowerCase()+AssembleSql.capture(SqlOperEnum.getValue(doStr)),
                    eventTypeObj.getString(eventType),xxSql);

        }
//        e_eventItem
        if (jsonObject.containsKey(children) && jsonObject.get(children) != null){
            JSONArray eventItems = jsonObject.getJSONArray(children);
            for (int i=0;i<eventItems.size();i++){
                JSONObject item = eventItems.getJSONObject(i);
                JSONObject eventItem = item.getJSONObject(e_eventItem);

                String functionValue = item.getString(e_function_key);
                String filed = eventItem.getString("eventItemCode");
                if (SqlKeyConst.BETWEEN.equals(functionValue)){
                    AssembleSql.assemleBetween(filed,
                            relation+AssembleSql.capture(SqlKeyConst.BETWEEN),
                            item.get(params_key),item.get(params2_key),xxSql);
                }else if(functionValue.contains(SqlKeyConst.IN)){
                    AssembleSql.assemleIn(filed,
                            relation+AssembleSql.capture(SqlOperEnum.getValue(functionValue)),
                            item.get(params_key),xxSql);
                }else {
                    AssembleSql.assemle(filed,
                            relation+AssembleSql.capture(SqlOperEnum.getValue(functionValue)),
                            item.get(params_key),xxSql);
                }
            }

        }

        if (jsonObject.containsKey("eventMethod") && jsonObject.get("eventMethod") != null
                && jsonObject.containsKey(e_function_key) && jsonObject.get(e_function_key) != null
                && jsonObject.containsKey(params_key) && jsonObject.get(params_key) != null){
            JSONArray methodArray = jsonObject.getJSONArray("eventMethod");

            if(methodArray.size()>1){
                String methodField = methodArray.getString(0);
                String method = methodArray.getString(1);
                //去重数
                if ("repeat".equals(method)){
                    return;
                }
                String function = jsonObject.getString(e_function_key);
                Object params = jsonObject.get(params_key);
                xxSql.and(" "+distinct_id+" in (");
                xxSql.select(" "+distinct_id+" ").from(" ( ");
                String havingField = method+"("+"toFloat32("+methodField+"))";
                xxSql.select(distinct_id).text(",").text(havingField);
                xxSql.from(table_events);
                xxSql.where("");
                if (StringUtil.isNotEmpty(startDate) && StringUtil.isNotEmpty(endDate)) {
                    AssembleSql.assemleBetween(s_f_time, SqlKeyConst.BETWEEN, startDate, endDate, xxSql);
                }
                xxSql.text(" and LENGTH("+methodField+") > 0 ");
                xxSql.groupBy(" "+distinct_id+" ");
                xxSql.having(" ");
                AssembleSql.assemle(havingField,SqlOperEnum.getValue(function),params,xxSql);
                xxSql.text(" ) aa");
                xxSql.text(" ) ");
            }
        }
    }

    private static void assemleOrderObj(JSONObject jsonObject,String globalRelation,String relation,String checkType,boolean isFirst,XxSqlQueryJoin xxSql){
        if (!jsonObject.containsKey(dataRange) || jsonObject.getJSONArray(dataRange) == null){
            return;
        }
//        if (!checkParamValue(jsonObject,userActionOrders)){
//            return;
//        }
        if (!isFirst){
            xxSql.unionAll();
        }
        //"dataRange":["2021-07-13","2021-07-29"]
        JSONArray range = jsonObject.getJSONArray(dataRange);
        String startDate = "";
        String endDate = "";
        if (!Objects.isNull(range) && !range.isEmpty()){
            startDate = range.getString(0);
            endDate = range.getString(1);
        }

        xxSql.select("user_id").as(distinct_id).from("(");
        xxSql.select("user_id").text(",").text("arrayWithConstant(`level`, 1) levels").
                text(",").text("arrayJoin(arrayEnumerate( levels )) level_index");
        xxSql.from("(");
        xxSql.select("user_id").text(",").text("windowFunnel(700000)").text("(");
        xxSql.text("dtime");
        JSONArray itemArray = jsonObject.getJSONArray(children);
        List<String> itemFileds = AssembleSql.getItemField(itemArray);
        for (int i = 0;i<itemArray.size();i++){

            xxSql.text(",");

            JSONObject item = itemArray.getJSONObject(i);
            JSONObject eventItem = item.getJSONObject(e_eventItem);
            AssembleSql.assemle(s_f_enent, XxBuildConst.EQUAL,eventItem.getString(eventType),xxSql);

            String functionValue = item.getString(e_function_key);
            String filed = eventItem.getString("eventItemCode");
            if (SqlKeyConst.BETWEEN.equals(functionValue)){
                AssembleSql.assemleBetween(filed,
                        relation+AssembleSql.capture(SqlKeyConst.BETWEEN),
                        item.get(params_key),item.get(params2_key),xxSql);
            }else if(functionValue.contains(SqlKeyConst.IN)){
                AssembleSql.assemleIn(filed,
                        relation+AssembleSql.capture(SqlOperEnum.getValue(functionValue)),
                        item.get(params_key),xxSql);
            }else {
                AssembleSql.assemle(filed,
                        relation+AssembleSql.capture(SqlOperEnum.getValue(functionValue)),
                        item.get(params_key),xxSql);
            }

        }
        //todo 事件集合及其它参数
        xxSql.text(")").as("`level`");
        xxSql.from("(");
        xxSql.select("toDate(`time`) as dtime,  event , "+distinct_id+" as user_id");
        if (!itemFileds.isEmpty()){
            xxSql.text(",");
            xxSql.text(String.join(",", itemFileds));
        }
        xxSql.from(table_events+" e");
        xxSql.where("LENGTH(`time`) > 0");
        if (StringUtil.isNotEmpty(startDate) && StringUtil.isNotEmpty(endDate)){
            xxSql.and("(").text("`time` ").text(" BETWEEN ").text("'").text(startDate).text("'")
//                            .and("toString(addDays(toDate(").text("'").text(endDate).text("'").text("),1)))");
                    .and("").text("'").text(endDate).text("'").text(")");
        }

        xxSql.text(")").groupBy("user_id");
        xxSql.text(")");
        xxSql.text(")").groupBy("user_id");

    }


    private static void assemleObject(JSONObject jsonObject,String paramModule,String globalRelation,String relation,XxSqlQueryJoin xxSql){

        if (checkParamValue(jsonObject,"")){
            String functionValue = jsonObject.getString(function_key);
            if (SqlKeyConst.BETWEEN.equals(functionValue)){
                Object bObj = jsonObject.get(params_key);
                String[] values = (String[])bObj;
                AssembleSql.assemleBetween(jsonObject.getString(field_key),
                        relation+ AssembleSql.capture(SqlKeyConst.BETWEEN),
                        values[0],values[1],xxSql);
            }else if(SqlKeyConst.IN.equals(functionValue)){
                AssembleSql.assemleIn(jsonObject.getString(field_key),
                        relation+AssembleSql.capture(SqlKeyConst.IN),
                        (List) jsonObject.get(params_key),xxSql);
            }else {
                AssembleSql.assemle(jsonObject.getString(field_key),
                        relation+AssembleSql.capture(SqlOperEnum.getValue(functionValue)),
                        jsonObject.get(params_key),xxSql);
            }

        }
        if (jsonObject.containsKey(children) && jsonObject.get(children) != null){
            assemleArray(jsonObject.getJSONArray(children),paramModule,globalRelation,
                    StringUtil.isNotEmpty(jsonObject.getString(relation))?jsonObject.getString(relation):SqlKeyConst.AND
                    ,xxSql);
        }

    }

    private static boolean checkParamValue(JSONObject jsonObject,String checkType){
        if (userActionOrders.equals(checkType)){
            if (jsonObject.containsKey(e_function_key) && jsonObject.containsKey(e_params_key)
                    && StringUtil.isNotEmpty(jsonObject.getString(e_function_key))
                    && !Objects.isNull(jsonObject.get(e_params_key))){
                return true;
            }
        }else if(userActions.equals(checkType)){
            if (jsonObject.containsKey(e_function_key) && jsonObject.containsKey(e_params_key)
                    && StringUtil.isNotEmpty(jsonObject.getString(e_function_key))
                    && !Objects.isNull(jsonObject.get(e_params_key))){
                return true;
            }
        }else{
            if (jsonObject.containsKey(field_key) && jsonObject.containsKey(function_key) && jsonObject.containsKey(params_key)
                    && StringUtil.isNotEmpty(jsonObject.getString(field_key))
                    && StringUtil.isNotEmpty(jsonObject.getString(function_key))){
                return true;
            }
        }

        return false;
    }

//    private static List<String> getItemField(JSONArray itemArray){
//        List<String> fields = new ArrayList<>();
//        for (int i = 0;i<itemArray.size();i++){
//            JSONObject item = itemArray.getJSONObject(i);
//            JSONObject eventItem = item.getJSONObject(e_eventItem);
//            String filed = eventItem.getString("eventItemCode");
//            fields.add(filed);
//        }
//
//        return fields;
//    }

    /**
     * 将字符串的首字母转大写
//     * @param str 需要转换的字符串
     * @return
     */
//    private static String capture(String str) {
//        // 进行字母的ascii编码前移，效率要高于截取字符串进行转换的操作
//        char[] cs=str.toCharArray();
//        cs[0]-=32;
//        return String.valueOf(cs);
//    }

//    private static void assemle(String filed,String function,Object params,XxSqlQueryJoin xxSql){
//        if (StringUtil.isEmpty(filed) || params == null
//                || StringUtil.isEmpty(function)){
//            return;
//        }
//        switch (function){
//            case XxBuildConst.EQUAL:
//                xxSql.equal(filed,params);
//                break;
//            case XxBuildConst.AND_EQUAL:
//                xxSql.andEqual(filed,params);
//                break;
//            case XxBuildConst.OR_EQUAL:
//                xxSql.orEqual(filed,params);
//                break;
//
//            case XxBuildConst.NOT_EQUAL:
//                xxSql.notEqual(filed,params);
//                break;
//            case XxBuildConst.AND_NOT_EQUAL:
//                xxSql.andNotEqual(filed,params);
//                break;
//            case XxBuildConst.OR_NOT_EQUAL:
//                xxSql.orNotEqual(filed,params);
//                break;
//
//            case XxBuildConst.MORE:
//                xxSql.moreThan(filed,params);
//                break;
//            case XxBuildConst.AND_MORE:
//                xxSql.andMoreThan(filed,params);
//                break;
//            case XxBuildConst.OR_MORE:
//                xxSql.orMoreThan(filed,params);
//                break;
//
//            case XxBuildConst.LESS:
//                xxSql.lessThan(filed,params);
//                break;
//            case XxBuildConst.AND_LESS:
//                xxSql.andLessThan(filed,params);
//                break;
//            case XxBuildConst.OR_LESS:
//                xxSql.orLessThan(filed,params);
//                break;
//
//            case XxBuildConst.MORE_EQUAL:
//                xxSql.moreEqual(filed,params);
//                break;
//            case XxBuildConst.AND_MORE_EQUAL:
//                xxSql.andMoreEqual(filed,params);
//                break;
//            case XxBuildConst.OR_MORE_EQUAL:
//                xxSql.orMoreEqual(filed,params);
//                break;
//
//            case XxBuildConst.LESS_EQUAL:
//                xxSql.lessEqual(filed,params);
//                break;
//            case XxBuildConst.AND_LESS_EQUAL:
//                xxSql.andLessEqual(filed,params);
//                break;
//            case XxBuildConst.OR_LESS_EQUAL:
//                xxSql.orLessEqual(filed,params);
//                break;
//
//            case XxBuildConst.LIKE:
//                xxSql.like(filed,params);
//                break;
//            case XxBuildConst.AND_LIKE:
//                xxSql.andLike(filed,params);
//                break;
//            case XxBuildConst.OR_LIKE:
//                xxSql.orLike(filed,params);
//                break;
//
//            case XxBuildConst.NOT_LIKE:
//                xxSql.notLike(filed,params);
//                break;
//            case XxBuildConst.AND_NOT_LIKE:
//                xxSql.andNotLike(filed,params);
//                break;
//            case XxBuildConst.OR_NOT_LIKE:
//                xxSql.orNotLike(filed,params);
//                break;
//
//            case XxBuildConst.IS_NULL:
//                xxSql.isNull(filed);
//                break;
//            case XxBuildConst.AND_IS_NULL:
//                xxSql.andIsNull(filed);
//                break;
//            case XxBuildConst.OR_IS_NULL:
//                xxSql.orIsNull(filed);
//                break;
//
//            case XxBuildConst.IS_NOT_NULL:
//                xxSql.isNotNull(filed);
//                break;
//            case XxBuildConst.AND_IS_NOT_NULL:
//                xxSql.andIsNotNull(filed);
//                break;
//            case XxBuildConst.OR_IS_NOT_NULL:
//                xxSql.orIsNotNull(filed);
//                break;
//            default:
//                return;
//        }
//    }

//    private static void assemleBetween(String filed,String function,Object startParam,Object endParam,XxSqlQueryJoin xxSql){
//        if (StringUtil.isEmpty(filed)
//                || StringUtil.isEmpty(function)){
//            return;
//        }
//        switch (function){
//            case XxBuildConst.BETWEEN:
//                xxSql.between(filed,startParam,endParam);
//                break;
//            case XxBuildConst.AND_BETWEEN:
//                xxSql.andBetween(filed,startParam,endParam);
//                break;
//            case XxBuildConst.OR_BETWEEN:
//                xxSql.orBetween(filed,startParam,endParam);
//                break;
//
//            default:
//                return;
//        }
//    }

//    private static void assemleIn(String filed, String function, Object value, XxSqlQueryJoin xxSql){
//        if (StringUtil.isEmpty(filed)
//                || StringUtil.isEmpty(function)){
//            return;
//        }
//        Object[] tmpValues=null;
//        if(value instanceof Array){
//            tmpValues=(Object[])value;
//        }
//        if(value instanceof Object[]){
//            tmpValues=(Object[])value;
//        }
//        if(value instanceof Collection){
//            tmpValues=((Collection<?>)value).toArray();
//        }
//        if(value instanceof String){
//            tmpValues = new Object[1];
//            tmpValues[0]=value;;
//        }
//        switch (function){
//            case XxBuildConst.IN:
//                xxSql.in(filed,tmpValues);
//                break;
//            case XxBuildConst.AND_IN:
//                xxSql.andIn(filed,tmpValues);
//                break;
//            case XxBuildConst.OR_IN:
//                xxSql.orIn(filed,tmpValues);
//                break;
//            case XxBuildConst.NOT_IN:
//                xxSql.notIn(filed,tmpValues);
//                break;
//            case XxBuildConst.AND_NOT_IN:
//                xxSql.andNotIn(filed,tmpValues);
//                break;
//            case XxBuildConst.OR_NOT_IN:
//                xxSql.orNotIn(filed,tmpValues);
//                break;
//
//            default:
//                return;
//        }
//    }


}
